<?php declare(strict_types=1);

/**
 * @package Dragula (Light Portal)
 * @link https://custom.simplemachines.org/index.php?mod=4244
 * @author Bugo <bugo@dragomano.ru>
 * @copyright 2024-2025 Bugo
 * @license https://opensource.org/licenses/MIT MIT
 *
 * @category plugin
 * @version 17.10.25
 */

namespace LightPortal\Plugins\Dragula;

use Bugo\Compat\Theme;
use Bugo\Compat\User;
use LightPortal\Enums\Placement;
use LightPortal\Plugins\Event;
use LightPortal\Plugins\Plugin;
use LightPortal\Plugins\PluginAttribute;

if (! defined('LP_NAME'))
	die('No direct access...');

/**
 * Generated by PluginMaker
 */
#[PluginAttribute]
class Dragula extends Plugin
{
	public function init(): void
	{
		if (! User::$me->allowedTo('admin_forum'))
			return;

		foreach (Placement::all() as $alias => $placement) {
			Theme::addInlineCss(PHP_EOL . "\t\t" . '[data-panel="' . $alias . '"].gu-over:before {
			content: "' . $placement . '";
		}');
		}

		$this->loadExternalResources([
			['type' => 'css', 'url' => 'https://cdn.jsdelivr.net/npm/dragula@3/dist/dragula.min.css'],
			['type' => 'js',  'url' => 'https://cdn.jsdelivr.net/npm/dragula@3/dist/dragula.min.js'],
		]);

		Theme::addInlineJavaScript('handleDragging()', true);
	}

	public function credits(Event $e): void
	{
		$e->args->links[] = [
			'title' => 'Dragula',
			'link' => 'https://github.com/bevacqua/dragula/',
			'author' => 'Nicolas Bevacqua',
			'license' => [
				'name' => 'the MIT License',
				'link' => 'https://github.com/bevacqua/dragula/?tab=MIT-1-ov-file#readme'
			]
		];
	}
}
